<template>
  <div :class="getComponentClass('sh-annex-small')" v-if="showEmptySub">
    <div class="category-file">
      <div class="category-count">{{ subCateData.data.fileList.length }}/{{ subCategoryItem.fileMaximum }}</div>
      <view-file
        v-for="(item, index) in subCateData.data.fileList"
        :key="`${item.fileId}${index}`"
        :attachmentConfigs="attachmentConfigs"
        :beforeDelete="beforeDelete"
        :file="item"
        @openProview="e => emits('openProview', e)"
        @deleteFile="deleteFile"
      ></view-file>
      <upload-file v-if="showUpload" :attachmentConfigs="attachmentConfigs" :beforeUpload="beforeUpload" @uploadSuccess="uploadSuccess" :subCategoryItem="subCategoryItem"></upload-file>
    </div>
    <p class="category-name" v-if="subCategoryItem.categoryName">{{ subCategoryItem.categoryName }}</p>
  </div>
</template>

<script setup>
import { useClass } from '../../utils/useClass';
import { useDependencyInjection } from '../../utils/useDependencyInjection';
import { useSubCategory } from './utils/useSubCategory';
import ViewFile from './view-file';
import UploadFile from './upload-file';
/**
 * @description: subCategoryItem 参数注解
 * deleteOperation: 是否可以删除
 * downloadOperation: 下载
 * fileFormat: 文件格式
 * fileList: file文件类型 Array
 * fileMaximum： 最大上传数量
 * fileMinimum: 最小上传数量
 * subCategoryCode: 小类code
 * subCategoryName: 小类名称
 * subCategoryStatus： 小类状态
 */
const { getComponentClass } = useClass();
const { getInject } = useDependencyInjection();

const props = defineProps({
  subCategoryItem: {
    type: Object,
    default: () => {
      return {
        fileMaximum: 0,
        fileList: [],
        subCategoryName: '',
      };
    },
  },
  attachmentConfigs: {
      type: Object,
      default: ()=> ( {
        showDelete: false,
        showUpload: true,
        showDown: true,
        showTopBar: false,
        showStandard: false,
        showApproveFlag: false,
        showAllBlank: false,
        showEmptySubclass: true,
        multiple: true
      })
    },
     /**
   * @description: 上传
   */
  beforeUpload: {
    type: Function,
    default: () => {},
  },
  beforeDelete: {
    type: Function,
    default: () => {},
  }
});
const emits = defineEmits(['openProview', 'uploadSuccess', 'deleteSuccess']);
const { showUpload, subCateData, deleteFile, uploadSuccess, showEmptySub } = useSubCategory(props, emits);
</script>

<style scoped lang="less"></style>
